package org.cosmact.designer.vxml.gefeditor.editpart.command;

import org.cosmact.vxml.model.Dialog;
import org.cosmact.vxml.model.Document;
import org.eclipse.gef.commands.Command;

public class DialogDeleteCommand extends Command {
	private Document parent;
	private Dialog dialog;

	public DialogDeleteCommand(final Document parent, final Dialog dialog) {
		this.parent = parent;
		this.dialog = dialog;
	}

	@Override
	public boolean canExecute() {
		return parent != null && dialog != null;
	}

	@Override
	public void execute() {
		parent.removeDialog(dialog);
	}

	@Override
	public void redo() {
		if (parent.getDialogs().contains(dialog)) {
			parent.removeDialog(dialog);
		}
	}

	@Override
	public void undo() {
		parent.addDialog(dialog);
	}

	@Override
	public boolean canUndo() {
		return !parent.getDialogs().contains(dialog);
	}

}
